﻿namespace GX
{
    public static class BitHelper
    {
        public static bool GetBit(int target, int index)
        {
            return 0 != ( target & (1 << index) );
        }
        public static void SetBit(ref int target, int index, bool value)
        {
            int mask = 1 << index;
            WriteMask(ref target,value ? mask:0,mask);
        }
        public static int ReadMask(int target, int mask)
        {
            return target & mask;
        }
        public static void WriteMask(ref int target, int value, int mask)
        {
            target &= ~mask;
            int toWriteValue = mask & value;
            target |= toWriteValue;
        }
    }
}